package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.dto.req.purchaseorder.GoDownExchangeDrugReqDTO;
import com.yixin.hospital.entity.dto.req.purchaseorder.GoDownExchangeDrugStatusReqDTO;
import com.yixin.hospital.service.GodownExchangeDrugService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/input-godown-exchange")
@Api(value = "调库单管理", tags = "调库单管理")
public class InputGodownExchangeController {

    @Resource
    private GodownExchangeDrugService godownExchangeDrugService;

    @GetMapping("/list2")
    @ApiOperation(value = "调库单列表")
    public ApiResult<?> list(HttpServletRequest request, @RequestParam int currentPage, @RequestParam int pageSize) {
        return godownExchangeDrugService.allList(request, currentPage, pageSize);
    }

    @GetMapping("/listInfo")
    @ApiOperation(value = "入库单详情")
    public ApiResult<?> ListInfo(@RequestParam String code) {
        return godownExchangeDrugService.listInfo(code);
    }

    @PostMapping("/godown-exchange-drug")
    @ApiOperation(value = "申请调库")
    @Transactional
    public ApiResult<?> goDownExchangeDrug(@Valid @RequestBody GoDownExchangeDrugReqDTO goDownDrugReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return godownExchangeDrugService.goDownExchangeDrug(goDownDrugReqDTO, userName);
    }

    @PostMapping("/godown-exchange-drug-status")
    @ApiOperation(value = "调库")
    @Transactional
    public ApiResult<?> goDownExchangeDrugStatus(@Valid @RequestBody GoDownExchangeDrugStatusReqDTO goDownExchangeDrugStatusReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return godownExchangeDrugService.goDownExchangeDrugStatus(goDownExchangeDrugStatusReqDTO, userName);
    }

}
